package cn.itcast.bos.mq;
import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.MessageListener;
import org.springframework.stereotype.Service;
import cn.itcast.bos.utils.SmsUtils;

@Service("smsConsumer")
public class SmsCunsumer implements MessageListener {

	//处理接受的消息,以及相应的业务
	@Override
	public void onMessage(Message message) {
		MapMessage mapMessage = (MapMessage) message;
		try {
			// 发送短信
			String telephone = mapMessage.getString("telephone");
			String content = mapMessage.getString("content");
			String result = SmsUtils.sendSmsByHTTP(telephone, content);
			// String result = "000/Send:1/Consumption:.1/Tmoney:1.8/sid:0706193801763554";
			if (result.startsWith("000")) {
				// 发送成功
				System.out.println("短信验证码发送成功!"+result);
			} else {
				// 发送失败
				throw new RuntimeException("发送验证码失败,错误码是:" + result);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
